﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Platform.Linq
{

	public struct ReducerFunction<TKey, TEmit>
	{
		private Expression<Func<IGrouping<TKey, TEmit>, TEmit>> reducer;
		private Func<IGrouping<TKey, TEmit>, TEmit> reducerCompiled;

		public ReducerFunction( Expression<Func<IGrouping<TKey, TEmit>, TEmit>> reducer )
		{
			this.reducer = reducer;
			this.reducerCompiled = null;
		}

		public Expression<Func<IGrouping<TKey, TEmit>, TEmit>> Expression
		{ get { return this.reducer; } }


		public Func<IGrouping<TKey, TEmit>, TEmit> Compiled
		{
			get
			{
				if ( this.reducerCompiled == null )
					this.reducerCompiled = this.reducer.Compile();
				return this.reducerCompiled;
			}
		}

	}
}
